home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0687.arc / BENCH.OBJ next >
Encoding:
Text File  |  1987-04-18  |  2.0 KB  |  73 lines

  1.  
  2. "Class implementing the Byte benchmarks.
  3.  
  4.  Written by Mat Davis."
  5.  
  6. Object subclass: #Benchmark
  7.   instanceVariableNames: ''
  8.   classVariableNames: ''
  9.   poolDictionaries: '' !
  10.  
  11. !Benchmark class methods ! !
  12.  
  13.  
  14. !Benchmark methods !
  15.  
  16. calculate: nTimes
  17.         "Perform the Byte calculation benchmark.  Using 'print it' with
  18.          the expression 'Benchmark new calculate: 5000' will print the
  19.          error after 5000 iterations."
  20.     | a b c |
  21.     a := 271828 / 100000.
  22.     b := 314159 / 100000.
  23.     c := 1.
  24.     1 to: nTimes do: [ :i |
  25.         c := c  a.
  26.         c := c  b.
  27.         c := c / a.
  28.         c := c / b ].
  29.     ^c - 1!
  30.  
  31. diskRead: kBytes
  32.         "Perform the Byte disk read benchmark.  Evaluating the expression
  33.          'Benchmark new diskRead: 64' will read a 64K from the file
  34.          A:TEST.DAT."
  35.     | nr input |
  36.     nr := kBytes  8.
  37.     input := DiskA file: 'TEST.DAT'.
  38.     1 to: nr do: [ :i |
  39.         input next: 128 ].
  40.     input close.
  41.     ^'Done'!
  42.  
  43. diskWrite: kBytes
  44.         "Perform the Byte disk write benchmark.  Evaluating the expression
  45.          'Benchmark new diskWrite: 64' will create a 64K file named
  46.          A:TEST.DAT."
  47.     | a b nr output |
  48.     a := '12345678123456781234567812345678'.
  49.     b := a, a, a, a.
  50.     nr := kBytes  8.
  51.     output := DiskA file: 'TEST.DAT'.
  52.     1 to: nr do: [ :i |
  53.         output nextPutAll: b ].
  54.     output close.
  55.     ^'Done'!
  56.  
  57. sieve: size
  58.         "Perform the Byte prime sieve benchmark.  Evaluating the expression
  59.          'Benchmark new sieve: 8191' will return the number of primes from
  60.          1 to 8191."
  61.     | flags count k |
  62.     flags := Array new: size.
  63.     count := 0.
  64.     1 to: size do: [ :i | flags at: i put: 1 ].
  65.     2 to: size do: [ :i |
  66.         (flags at: i) == 1 ifTrue: [
  67.             k := i + i.
  68.             [ k > size ] whileFalse: [
  69.                 flags at: k put: 0.
  70.                 k := k + i ].
  71.             count := count + 1 ] ].
  72.     ^count! !
  73.